package vshevchuk;

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class XMLtest {
	
	public boolean LoadXml (String name) throws Exception {
		
		String str;
		boolean return_value=true;
		int i=0, count1=0, count2=0, count3=0;
		
		try{
			BufferedReader in = new BufferedReader(new FileReader(name));
			
			while((str = in.readLine()) != null){
				count1=str.split("<").length-1;
				count2=str.split(">").length;
				count3=str.split("</").length-1;
			
				if ((count3>1 && count1/2!=count3) || count3==1 && count1!=count3) {
					return_value=false;
					break;
				}
				if (count1!=count2) {
					return_value=false;
					break;
				}
			}	
		
			return return_value;
		}
		
    	catch(FileNotFoundException e){
        	return false;
    	}
	}
		
	public static void main (String[] avgs) throws Exception {
		XMLtest A = new XMLtest ();
		System.out.println(A.LoadXml("res.xml"));
	}

}
